package com.iengoo.edu.dao;

import com.iengoo.edu.entity.Emp;
import org.junit.Test;

import java.io.IOException;
import java.sql.SQLException;
import java.util.*;

import static org.junit.Assert.*;

public class EmpDao2Test {


    @Test
    public void testMap() throws IOException {
//        Map map = new HashMap();
//        map.put("keu", "va");
//
//        Properties properties = new Properties();
//        properties.put("name", "张三");
//        Object name = properties.get("name");
//        String name1 = properties.getProperty("name");
//        String password = properties.getProperty("password", "123456");
//        System.out.println(name);

        // 创建配置文件对象
        Properties prop = new Properties();
        // 从EmpDao2Test.class类所在的路径中去加载配置文件，并把配置文件作为IO 流提供给 prop对象使用
        prop.load(EmpDao2Test.class.getResourceAsStream("jdbc.properties"));
        // 从ClassLoader（类加载器）加载类的路径（即从src开始查找）中去加载配置文件，并把配置文件作为IO 流提供给 prop对象使用
        prop.load(EmpDao2Test.class.getClassLoader().getResourceAsStream("jdbc.properties"));

        String username = prop.getProperty("username");
        System.out.println(Config.password);
    }

    @Test
    public void testGeneric() {
        List<Integer> list = new ArrayList();
        // E --> element --> 元素
        // T --> type ---> 类型
        // K --> KEY  ---> 键
        // V --> Value  ---> 值
        list.add(111);

        for (Object o : list) {

        }
    }
}

class Order implements Comparator<Integer>{

    @Override
    public int compare(Integer o1, Integer o2) {
        return 0;
    }
}

class Config {
    public static String username;
    public static String password;

    static {
        Properties prop = new Properties();
        try {
            prop.load(EmpDao2Test.class.getClassLoader().getResourceAsStream("jdbc.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        username = prop.getProperty("username");
        password = prop.getProperty("password");
    }

    public void t() {
        Factory<String> factory = new Factory<>();
        String instance = factory.getInstance(String.class);
    }
}

class Factory<T>{
    public T getInstance(Class<T> type) {
        T t = null;
        try {
            t = type.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return t;
    }

//    public String getInstance(Class type) throws IllegalAccessException, InstantiationException {
//        return (String)type.newInstance();
//    }
//
//    public Integer getInstance2(Class type) throws IllegalAccessException, InstantiationException {
//        return (Integer)type.newInstance();
//    }
//
}
